<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This file documents the use of the GNU compilers.

Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Function Attributes (Using the GNU Compiler Collection (GCC))</title>

<meta name="description" content="Function Attributes (Using the GNU Compiler Collection (GCC))">
<meta name="keywords" content="Function Attributes (Using the GNU Compiler Collection (GCC))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Indices.html" rel="index" title="Indices">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="C-Extensions.html" rel="up" title="C Extensions">
<link href="Variable-Attributes.html" rel="next" title="Variable Attributes">
<link href="Mixed-Labels-and-Declarations.html" rel="prev" title="Mixed Labels and Declarations">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
kbd.key {font-style: normal}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en_US">
<div class="section-level-extent" id="Function-Attributes">
<div class="nav-panel">
<p>
Next: <a href="Variable-Attributes.html" accesskey="n" rel="next">Specifying Attributes of Variables</a>, Previous: <a href="Mixed-Labels-and-Declarations.html" accesskey="p" rel="prev">Mixed Declarations, Labels and Code</a>, Up: <a href="C-Extensions.html" accesskey="u" rel="up">Extensions to the C Language Family</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Declaring-Attributes-of-Functions"><span>6.33 Declaring Attributes of Functions<a class="copiable-link" href="#Declaring-Attributes-of-Functions"> &para;</a></span></h3>
<a class="index-entry-id" id="index-function-attributes"></a>
<a class="index-entry-id" id="index-declaring-attributes-of-functions"></a>
<a class="index-entry-id" id="index-volatile-applied-to-function"></a>
<a class="index-entry-id" id="index-const-applied-to-function"></a>

<p>In GNU C and C++, you can use function attributes to specify certain
function properties that may help the compiler optimize calls or
check code more carefully for correctness.  For example, you
can use attributes to specify that a function never returns
(<code class="code">noreturn</code>), returns a value depending only on the values of
its arguments (<code class="code">const</code>), or has <code class="code">printf</code>-style arguments
(<code class="code">format</code>).
</p>
<p>You can also use attributes to control memory placement, code
generation options or call/return conventions within the function
being annotated.  Many of these attributes are target-specific.  For
example, many targets support attributes for defining interrupt
handler functions, which typically must follow special register usage
and return conventions.  Such attributes are described in the subsection
for each target.  However, a considerable number of attributes are
supported by most, if not all targets.  Those are described in
the <a class="ref" href="Common-Function-Attributes.html">Common Function Attributes</a> section.
</p>
<p>Function attributes are introduced by the <code class="code">__attribute__</code> keyword
in the declaration of a function, followed by an attribute specification
enclosed in double parentheses.  You can specify multiple attributes in
a declaration by separating them by commas within the double parentheses
or by immediately following one attribute specification with another.
See <a class="xref" href="Attribute-Syntax.html">Attribute Syntax</a>, for the exact rules on attribute syntax and
placement.  Compatible attribute specifications on distinct declarations
of the same function are merged.  An attribute specification that is not
compatible with attributes already applied to a declaration of the same
function is ignored with a warning.
</p>
<p>Some function attributes take one or more arguments that refer to
the function&rsquo;s parameters by their positions within the function parameter
list.  Such attribute arguments are referred to as <em class="dfn">positional arguments</em>.
Unless specified otherwise, positional arguments that specify properties
of parameters with pointer types can also specify the same properties of
the implicit C++ <code class="code">this</code> argument in non-static member functions, and
of parameters of reference to a pointer type.  For ordinary functions,
position one refers to the first parameter on the list.  In C++ non-static
member functions, position one refers to the implicit <code class="code">this</code> pointer.
The same restrictions and effects apply to function attributes used with
ordinary functions or C++ member functions.
</p>
<p>GCC also supports attributes on
variable declarations (see <a class="pxref" href="Variable-Attributes.html">Specifying Attributes of Variables</a>),
labels (see <a class="pxref" href="Label-Attributes.html">Label Attributes</a>),
enumerators (see <a class="pxref" href="Enumerator-Attributes.html">Enumerator Attributes</a>),
statements (see <a class="pxref" href="Statement-Attributes.html">Statement Attributes</a>),
types (see <a class="pxref" href="Type-Attributes.html">Specifying Attributes of Types</a>),
and on field declarations (for <code class="code">tainted_args</code>).
</p>
<p>There is some overlap between the purposes of attributes and pragmas
(see <a class="pxref" href="Pragmas.html">Pragmas Accepted by GCC</a>).  It has been
found convenient to use <code class="code">__attribute__</code> to achieve a natural
attachment of attributes to their corresponding declarations, whereas
<code class="code">#pragma</code> is of use for compatibility with other compilers
or constructs that do not naturally form part of the grammar.
</p>
<p>In addition to the attributes documented here,
GCC plugins may provide their own attributes.
</p>

<ul class="mini-toc">
<li><a href="Common-Function-Attributes.html" accesskey="1">Common Function Attributes</a></li>
<li><a href="AArch64-Function-Attributes.html" accesskey="2">AArch64 Function Attributes</a></li>
<li><a href="AMD-GCN-Function-Attributes.html" accesskey="3">AMD GCN Function Attributes</a></li>
<li><a href="ARC-Function-Attributes.html" accesskey="4">ARC Function Attributes</a></li>
<li><a href="ARM-Function-Attributes.html" accesskey="5">ARM Function Attributes</a></li>
<li><a href="AVR-Function-Attributes.html" accesskey="6">AVR Function Attributes</a></li>
<li><a href="Blackfin-Function-Attributes.html" accesskey="7">Blackfin Function Attributes</a></li>
<li><a href="BPF-Function-Attributes.html" accesskey="8">BPF Function Attributes</a></li>
<li><a href="C_002dSKY-Function-Attributes.html" accesskey="9">C-SKY Function Attributes</a></li>
<li><a href="Epiphany-Function-Attributes.html">Epiphany Function Attributes</a></li>
<li><a href="H8_002f300-Function-Attributes.html">H8/300 Function Attributes</a></li>
<li><a href="IA_002d64-Function-Attributes.html">IA-64 Function Attributes</a></li>
<li><a href="M32C-Function-Attributes.html">M32C Function Attributes</a></li>
<li><a href="M32R_002fD-Function-Attributes.html">M32R/D Function Attributes</a></li>
<li><a href="m68k-Function-Attributes.html">m68k Function Attributes</a></li>
<li><a href="MCORE-Function-Attributes.html">MCORE Function Attributes</a></li>
<li><a href="MicroBlaze-Function-Attributes.html">MicroBlaze Function Attributes</a></li>
<li><a href="Microsoft-Windows-Function-Attributes.html">Microsoft Windows Function Attributes</a></li>
<li><a href="MIPS-Function-Attributes.html">MIPS Function Attributes</a></li>
<li><a href="MSP430-Function-Attributes.html">MSP430 Function Attributes</a></li>
<li><a href="NDS32-Function-Attributes.html">NDS32 Function Attributes</a></li>
<li><a href="Nios-II-Function-Attributes.html">Nios II Function Attributes</a></li>
<li><a href="Nvidia-PTX-Function-Attributes.html">Nvidia PTX Function Attributes</a></li>
<li><a href="PowerPC-Function-Attributes.html">PowerPC Function Attributes</a></li>
<li><a href="RISC_002dV-Function-Attributes.html">RISC-V Function Attributes</a></li>
<li><a href="RL78-Function-Attributes.html">RL78 Function Attributes</a></li>
<li><a href="RX-Function-Attributes.html">RX Function Attributes</a></li>
<li><a href="S_002f390-Function-Attributes.html">S/390 Function Attributes</a></li>
<li><a href="SH-Function-Attributes.html">SH Function Attributes</a></li>
<li><a href="Symbian-OS-Function-Attributes.html">Symbian OS Function Attributes</a></li>
<li><a href="V850-Function-Attributes.html">V850 Function Attributes</a></li>
<li><a href="Visium-Function-Attributes.html">Visium Function Attributes</a></li>
<li><a href="x86-Function-Attributes.html">x86 Function Attributes</a></li>
<li><a href="Xstormy16-Function-Attributes.html">Xstormy16 Function Attributes</a></li>
</ul>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Variable-Attributes.html">Specifying Attributes of Variables</a>, Previous: <a href="Mixed-Labels-and-Declarations.html">Mixed Declarations, Labels and Code</a>, Up: <a href="C-Extensions.html">Extensions to the C Language Family</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
